package com.limao.Tool;


import com.limao.CacheManager.CrowdUserAuthCache;
import com.limao.DBDataClass.CrowdUserAuthClass;
import com.limao.Model.LzPluginException;
import com.limao.dataEnum.SMSTypeEnum;


public class SMSUtil {
	private static String smsParamName="SMS";

	//发短信到用户
	public static boolean SendSMS(int id,String sms) throws LzPluginException
	{
		boolean success=false;
		CrowdUserAuthClass user = CrowdUserAuthCache.getInstance().getUser(id);
		if(user==null || CacheClass.isEmpty(user.mobile) || !CacheClass.isMobileNO(user.mobile))
		{
			return success;
		}
		
		return sendSMS(user.mobile,sms);
	}
	
	public static boolean sendSMS(String mobile,String sms) throws LzPluginException
	{
		return send(mobile,sms);
	}
	
	private static boolean send(String mobile,String code) throws LzPluginException
	{
		if (CacheClass.ISDEBUG==1)
		{
			return true;
		}
		
		String smsParamstr=CacheClass.getSYS_BaseDataCacheManager().Load_Param(smsParamName);
		SMSTypeEnum smsParam =SMSTypeEnum.getEnum(smsParamstr);
		boolean result=false;
		switch (smsParam) {
		case webchinese:
			result =SMSWebchinese.send(mobile, code);
			break;
		case cloopen:
			result =SMSCloopen.send(mobile, code);
			break;
		case dxt:
			result =SMSDuanXT.send(mobile, code);
			break;
		case huyi:
			result =SMSHuyi.send(mobile, code);
			break;
		case aliyun:
			result =SMSAliyun.send(mobile, code);
			break;
		default:
			break;
		}
		
		return result;
	}

}
